﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CorporateGym.DAL;

namespace BLL.Managers
{
    public class GymLoginManager
    {
        private static GymLoginManager m_This;
        private static readonly object sr_SyncObj = new Object();
        public static GymLoginManager Instance
        {
            get
            {
                if (m_This == null)
                {
                    lock (sr_SyncObj)
                    {
                        if (m_This == null)
                        {
                            m_This = new GymLoginManager();
                        }
                    }
                }

                return m_This;
            }
        }

        private GymLoginManager()
        {
            DataAccess.Instance.Init();
        }

        public GymWorker LoggedinUser { get; private set; }

        public GymWorker Login(string i_UserName, string i_Password)
        {
            GymWorker worker = null;

            int workerId = DataAccess.Instance.CheckUserNamePassword(i_UserName, i_Password); 
            if(workerId != -1)
            {
                worker = GymWorkerManager.Instance.GetWorkerById(workerId);
            }

            LoggedinUser = worker;
            return worker;
        }

        public void LogOut()
        {
            DataAccess.Instance.SaveData();
            LoggedinUser = null;
        }
    }
}
